//
//  AppCommonTool.m
//  SMealHourseMan
//
//  Created by apple on 2018/5/19.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "AppCommonTool.h"

@implementation AppCommonTool
/**
 版本检测更新
 
 @param severVersion 服务器app版本
 @param currenVersion 系统版本
 @return 是否更新
 */
+ (BOOL)chekAppVersionUpdateWithSeverVersion:(NSString *)severVersion currentVersion:(NSString *)currenVersion
{
    if(severVersion.length == 0) return NO;
    if(currenVersion.length == 0){
        currenVersion = [AppConstants getCurrentAppVersion];
    }
    
    NSArray *severVersionArray = [severVersion componentsSeparatedByString:@"."];
    NSArray *currentVersionArray = [currenVersion componentsSeparatedByString:@"."];
    if(severVersionArray.count == 0||currentVersionArray.count ==0){
        return NO;
    }
    NSInteger count = MIN(severVersionArray.count, currentVersionArray.count);
    
    //遍历版本号
    for (NSInteger i = 0; i < count; i++) {
        //服务器版本
        NSInteger severV = [[severVersionArray objectAtIndex:i] integerValue];
        //系统当前版本
        NSInteger currentV = [[currentVersionArray objectAtIndex:i] integerValue];
        
        if(severV > currentV){
            return YES;
        }
        if(severV < currentV){
            return NO;
        }
    }
    
    //如果服务器的版本号大于系统的版本号
    if(severVersionArray.count > currentVersionArray.count){
        for (NSInteger i=currentVersionArray.count; i<severVersionArray.count; i++) {
            NSInteger verion = [[severVersionArray objectAtIndex:i] integerValue];
            if (verion>0) {
                return YES;
            }
        }
    }

    return NO;
}
@end
